package cn.powerone.scm.controller;

import java.util.List;

import cn.powerone.scm.domain.ScmSupplierOrderItemsWithOrderInfoVO;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.powerone.common.annotation.Log;
import cn.powerone.common.core.controller.BaseController;
import cn.powerone.common.core.domain.AjaxResult;
import cn.powerone.common.enums.BusinessType;
import cn.powerone.scm.domain.ScmSupplierOrderItems;
import cn.powerone.scm.service.IScmSupplierOrderItemsService;
import cn.powerone.common.utils.poi.ExcelUtil;
import cn.powerone.common.core.page.TableDataInfo;

/**
 * 供应商订单明细Controller
 * 
 * @author PowerOne
 * @date 2025-07-04
 */
@RestController
@RequestMapping("/scm/scmSupplierOrderItems")
public class ScmSupplierOrderItemsController extends BaseController
{
    @Autowired
    private IScmSupplierOrderItemsService scmSupplierOrderItemsService;

    /**
     * 查询供应商订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('scm:scmSupplierOrderItems:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmSupplierOrderItems scmSupplierOrderItems)
    {
        startPage();
        List<ScmSupplierOrderItems> list = scmSupplierOrderItemsService.selectScmSupplierOrderItemsList(scmSupplierOrderItems);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('scm:scmSupplierOrderItems:list')")
    @GetMapping("/listSupplierOrderItemsWithOrderInfo")
    public TableDataInfo listWithOrderInfo(ScmSupplierOrderItemsWithOrderInfoVO scmSupplierOrderItems) {
        startPage();
        List<ScmSupplierOrderItemsWithOrderInfoVO> list = scmSupplierOrderItemsService.selectScmSupplierOrderItemsListWithOrderInfo(scmSupplierOrderItems);
        return getDataTable(list);
    }


    /**
     * 导出供应商订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('scm:scmSupplierOrderItems:export')")
    @Log(title = "供应商订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmSupplierOrderItems scmSupplierOrderItems)
    {
        List<ScmSupplierOrderItems> list = scmSupplierOrderItemsService.selectScmSupplierOrderItemsList(scmSupplierOrderItems);
        ExcelUtil<ScmSupplierOrderItems> util = new ExcelUtil<ScmSupplierOrderItems>(ScmSupplierOrderItems.class);
        util.exportExcel(response, list, "供应商订单明细数据");
    }

    /**
     * 获取供应商订单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('scm:scmSupplierOrderItems:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(scmSupplierOrderItemsService.selectScmSupplierOrderItemsByItemId(itemId));
    }

    /**
     * 新增供应商订单明细
     */
    @PreAuthorize("@ss.hasPermi('scm:scmSupplierOrderItems:add')")
    @Log(title = "供应商订单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmSupplierOrderItems scmSupplierOrderItems)
    {
        return toAjax(scmSupplierOrderItemsService.insertScmSupplierOrderItems(scmSupplierOrderItems));
    }

    /**
     * 修改供应商订单明细
     */
    @PreAuthorize("@ss.hasPermi('scm:scmSupplierOrderItems:edit')")
    @Log(title = "供应商订单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmSupplierOrderItems scmSupplierOrderItems)
    {
        return toAjax(scmSupplierOrderItemsService.updateScmSupplierOrderItems(scmSupplierOrderItems));
    }

    /**
     * 删除供应商订单明细
     */
    @PreAuthorize("@ss.hasPermi('scm:scmSupplierOrderItems:remove')")
    @Log(title = "供应商订单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(scmSupplierOrderItemsService.deleteScmSupplierOrderItemsByItemIds(itemIds));
    }
}
